<test>
  <sql>SELECT  e.FirstName + ' ' + e.LastName AS Emp,
        t.*
FROM    EmployeeTerritories et
            INNER JOIN Employees e ON e.EmployeeID = et.EmployeeID
            RIGHT JOIN Territories t ON t.TerritoryID = et.TerritoryID
WHERE EXISTS (
    SELECT  COUNT(*)
    FROM    Products p
    WHERE   p.CategoryID = LEN(e.LastName)

)
AND t.RegionID = 1
OR  NOT EXISTS (
    SELECT  *
    FROM    EmployeeTerritories et
    WHERE   et.TerritoryID = t.TerritoryID
)
ORDER  BY 1, 2, 3, 4</sql>
  <expectedResults>
    <NewDataSet>
  <xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table1" msdata:Locale="en-US">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Emp" type="xs:string" minOccurs="0" />
                <xs:element name="TerritoryID" type="xs:string" minOccurs="0" />
                <xs:element name="TerritoryDescription" type="xs:string" minOccurs="0" />
                <xs:element name="RegionID" type="xs:int" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table1>
    <TerritoryID>29202</TerritoryID>
    <TerritoryDescription>Columbia                                          </TerritoryDescription>
    <RegionID>4</RegionID>
  </Table1>
  <Table1>
    <TerritoryID>72716</TerritoryID>
    <TerritoryDescription>Bentonville                                       </TerritoryDescription>
    <RegionID>4</RegionID>
  </Table1>
  <Table1>
    <TerritoryID>75234</TerritoryID>
    <TerritoryDescription>Dallas                                            </TerritoryDescription>
    <RegionID>4</RegionID>
  </Table1>
  <Table1>
    <TerritoryID>78759</TerritoryID>
    <TerritoryDescription>Austin                                            </TerritoryDescription>
    <RegionID>4</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>01581</TerritoryID>
    <TerritoryDescription>Westboro                                          </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>01730</TerritoryID>
    <TerritoryDescription>Bedford                                           </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>01833</TerritoryID>
    <TerritoryDescription>Georgetow                                         </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>02116</TerritoryID>
    <TerritoryDescription>Boston                                            </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>02139</TerritoryID>
    <TerritoryDescription>Cambridge                                         </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>02184</TerritoryID>
    <TerritoryDescription>Braintree                                         </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Andrew Fuller</Emp>
    <TerritoryID>40222</TerritoryID>
    <TerritoryDescription>Louisville                                        </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Margaret Peacock</Emp>
    <TerritoryID>20852</TerritoryID>
    <TerritoryDescription>Rockville                                         </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Margaret Peacock</Emp>
    <TerritoryID>27403</TerritoryID>
    <TerritoryDescription>Greensboro                                        </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Margaret Peacock</Emp>
    <TerritoryID>27511</TerritoryID>
    <TerritoryDescription>Cary                                              </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Nancy Davolio</Emp>
    <TerritoryID>06897</TerritoryID>
    <TerritoryDescription>Wilton                                            </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Nancy Davolio</Emp>
    <TerritoryID>19713</TerritoryID>
    <TerritoryDescription>Neward                                            </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>02903</TerritoryID>
    <TerritoryDescription>Providence                                        </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>07960</TerritoryID>
    <TerritoryDescription>Morristown                                        </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>08837</TerritoryID>
    <TerritoryDescription>Edison                                            </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>10019</TerritoryID>
    <TerritoryDescription>New York                                          </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>10038</TerritoryID>
    <TerritoryDescription>New York                                          </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>11747</TerritoryID>
    <TerritoryDescription>Mellvile                                          </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
  <Table1>
    <Emp>Steven Buchanan</Emp>
    <TerritoryID>14450</TerritoryID>
    <TerritoryDescription>Fairport                                          </TerritoryDescription>
    <RegionID>1</RegionID>
  </Table1>
</NewDataSet>
  </expectedResults>
  <expectedPlan>
    <executionPlan>
      <element operator="Select">
        <properties>
          <property name="Output List.[0]" value="Expr1008 AS Emp" />
          <property name="Output List.[0].Column" value="Expr1008" />
          <property name="Output List.[0].DataType" value="String" />
          <property name="Output List.[0].Output Name" value="Emp" />
          <property name="Output List.[1]" value="t.TerritoryID AS TerritoryID" />
          <property name="Output List.[1].Table" value="t" />
          <property name="Output List.[1].Column" value="TerritoryID" />
          <property name="Output List.[1].DataType" value="String" />
          <property name="Output List.[1].Output Name" value="TerritoryID" />
          <property name="Output List.[2]" value="t.TerritoryDescription AS TerritoryDescription" />
          <property name="Output List.[2].Table" value="t" />
          <property name="Output List.[2].Column" value="TerritoryDescription" />
          <property name="Output List.[2].DataType" value="String" />
          <property name="Output List.[2].Output Name" value="TerritoryDescription" />
          <property name="Output List.[3]" value="t.RegionID AS RegionID" />
          <property name="Output List.[3].Table" value="t" />
          <property name="Output List.[3].Column" value="RegionID" />
          <property name="Output List.[3].DataType" value="Int32" />
          <property name="Output List.[3].Output Name" value="RegionID" />
        </properties>
        <input>
          <element operator="Sort">
            <properties>
              <property name="Output List.[0]" value="t.TerritoryID" />
              <property name="Output List.[0].Table" value="t" />
              <property name="Output List.[0].Column" value="TerritoryID" />
              <property name="Output List.[0].DataType" value="String" />
              <property name="Output List.[1]" value="t.TerritoryDescription" />
              <property name="Output List.[1].Table" value="t" />
              <property name="Output List.[1].Column" value="TerritoryDescription" />
              <property name="Output List.[1].DataType" value="String" />
              <property name="Output List.[2]" value="t.RegionID" />
              <property name="Output List.[2].Table" value="t" />
              <property name="Output List.[2].Column" value="RegionID" />
              <property name="Output List.[2].DataType" value="Int32" />
              <property name="Output List.[3]" value="Expr1008" />
              <property name="Output List.[3].Column" value="Expr1008" />
              <property name="Output List.[3].DataType" value="String" />
              <property name="Statistics.Open Count" value="1" />
              <property name="Statistics.Row Count" value="23" />
              <property name="Statistics.Average Row Count" value="23" />
              <property name="Logical Operator" value="Sort" />
              <property name="Order By.[0]" value="Expr1008 ASC" />
              <property name="Order By.[0].Column" value="Expr1008" />
              <property name="Order By.[0].DataType" value="String" />
              <property name="Order By.[0].Order" value="ASC" />
              <property name="Order By.[1]" value="t.TerritoryID ASC" />
              <property name="Order By.[1].Table" value="t" />
              <property name="Order By.[1].Column" value="TerritoryID" />
              <property name="Order By.[1].DataType" value="String" />
              <property name="Order By.[1].Order" value="ASC" />
              <property name="Order By.[2]" value="t.TerritoryDescription ASC" />
              <property name="Order By.[2].Table" value="t" />
              <property name="Order By.[2].Column" value="TerritoryDescription" />
              <property name="Order By.[2].DataType" value="String" />
              <property name="Order By.[2].Order" value="ASC" />
              <property name="Order By.[3]" value="t.RegionID ASC" />
              <property name="Order By.[3].Table" value="t" />
              <property name="Order By.[3].Column" value="RegionID" />
              <property name="Order By.[3].DataType" value="Int32" />
              <property name="Order By.[3].Order" value="ASC" />
            </properties>
            <input>
              <element operator="NestedLoops">
                <properties>
                  <property name="Output List.[0]" value="t.TerritoryID" />
                  <property name="Output List.[0].Table" value="t" />
                  <property name="Output List.[0].Column" value="TerritoryID" />
                  <property name="Output List.[0].DataType" value="String" />
                  <property name="Output List.[1]" value="t.TerritoryDescription" />
                  <property name="Output List.[1].Table" value="t" />
                  <property name="Output List.[1].Column" value="TerritoryDescription" />
                  <property name="Output List.[1].DataType" value="String" />
                  <property name="Output List.[2]" value="t.RegionID" />
                  <property name="Output List.[2].Table" value="t" />
                  <property name="Output List.[2].Column" value="RegionID" />
                  <property name="Output List.[2].DataType" value="Int32" />
                  <property name="Output List.[3]" value="Expr1008" />
                  <property name="Output List.[3].Column" value="Expr1008" />
                  <property name="Output List.[3].DataType" value="String" />
                  <property name="Logical Operator" value="Left Semi Join" />
                  <property name="Statistics.Open Count" value="1" />
                  <property name="Statistics.Row Count" value="23" />
                  <property name="Statistics.Average Row Count" value="23" />
                  <property name="Outer References.[0]" value="t.RegionID" />
                  <property name="Outer References.[0].Table" value="t" />
                  <property name="Outer References.[0].Column" value="RegionID" />
                  <property name="Outer References.[0].DataType" value="Int32" />
                  <property name="Outer References.[1]" value="t.TerritoryID" />
                  <property name="Outer References.[1].Table" value="t" />
                  <property name="Outer References.[1].Column" value="TerritoryID" />
                  <property name="Outer References.[1].DataType" value="String" />
                </properties>
                <input>
                  <element operator="ComputeScalar">
                    <properties>
                      <property name="Output List.[0]" value="t.TerritoryID" />
                      <property name="Output List.[0].Table" value="t" />
                      <property name="Output List.[0].Column" value="TerritoryID" />
                      <property name="Output List.[0].DataType" value="String" />
                      <property name="Output List.[1]" value="t.TerritoryDescription" />
                      <property name="Output List.[1].Table" value="t" />
                      <property name="Output List.[1].Column" value="TerritoryDescription" />
                      <property name="Output List.[1].DataType" value="String" />
                      <property name="Output List.[2]" value="t.RegionID" />
                      <property name="Output List.[2].Table" value="t" />
                      <property name="Output List.[2].Column" value="RegionID" />
                      <property name="Output List.[2].DataType" value="Int32" />
                      <property name="Output List.[3]" value="Expr1008" />
                      <property name="Output List.[3].Column" value="Expr1008" />
                      <property name="Output List.[3].DataType" value="String" />
                      <property name="Statistics.Open Count" value="1" />
                      <property name="Statistics.Row Count" value="53" />
                      <property name="Statistics.Average Row Count" value="53" />
                      <property name="Defined Values.[0]" value="Expr1008 = e.FirstName + ' ' + e.LastName" />
                      <property name="Defined Values.[0].Target" value="Expr1008" />
                      <property name="Defined Values.[0].DataType" value="String" />
                      <property name="Defined Values.[0].Source" value="e.FirstName + ' ' + e.LastName" />
                    </properties>
                    <input>
                      <element operator="HashMatch">
                        <properties>
                          <property name="Output List.[0]" value="e.LastName" />
                          <property name="Output List.[0].Table" value="e" />
                          <property name="Output List.[0].Column" value="LastName" />
                          <property name="Output List.[0].DataType" value="String" />
                          <property name="Output List.[1]" value="e.FirstName" />
                          <property name="Output List.[1].Table" value="e" />
                          <property name="Output List.[1].Column" value="FirstName" />
                          <property name="Output List.[1].DataType" value="String" />
                          <property name="Output List.[2]" value="t.TerritoryID" />
                          <property name="Output List.[2].Table" value="t" />
                          <property name="Output List.[2].Column" value="TerritoryID" />
                          <property name="Output List.[2].DataType" value="String" />
                          <property name="Output List.[3]" value="t.TerritoryDescription" />
                          <property name="Output List.[3].Table" value="t" />
                          <property name="Output List.[3].Column" value="TerritoryDescription" />
                          <property name="Output List.[3].DataType" value="String" />
                          <property name="Output List.[4]" value="t.RegionID" />
                          <property name="Output List.[4].Table" value="t" />
                          <property name="Output List.[4].Column" value="RegionID" />
                          <property name="Output List.[4].DataType" value="Int32" />
                          <property name="Statistics.Open Count" value="1" />
                          <property name="Statistics.Row Count" value="53" />
                          <property name="Statistics.Average Row Count" value="53" />
                          <property name="Hash Keys Build" value="et.TerritoryID" />
                          <property name="Hash Keys Build.Table" value="et" />
                          <property name="Hash Keys Build.Column" value="TerritoryID" />
                          <property name="Hash Keys Build.DataType" value="String" />
                          <property name="Hash Keys Probe" value="t.TerritoryID" />
                          <property name="Hash Keys Probe.Table" value="t" />
                          <property name="Hash Keys Probe.Column" value="TerritoryID" />
                          <property name="Hash Keys Probe.DataType" value="String" />
                          <property name="Logical Operator" value="Right Outer Join" />
                        </properties>
                        <input>
                          <element operator="HashMatch">
                            <properties>
                              <property name="Output List.[0]" value="e.LastName" />
                              <property name="Output List.[0].Table" value="e" />
                              <property name="Output List.[0].Column" value="LastName" />
                              <property name="Output List.[0].DataType" value="String" />
                              <property name="Output List.[1]" value="e.FirstName" />
                              <property name="Output List.[1].Table" value="e" />
                              <property name="Output List.[1].Column" value="FirstName" />
                              <property name="Output List.[1].DataType" value="String" />
                              <property name="Output List.[2]" value="et.TerritoryID" />
                              <property name="Output List.[2].Table" value="et" />
                              <property name="Output List.[2].Column" value="TerritoryID" />
                              <property name="Output List.[2].DataType" value="String" />
                              <property name="Statistics.Open Count" value="1" />
                              <property name="Statistics.Row Count" value="49" />
                              <property name="Statistics.Average Row Count" value="49" />
                              <property name="Hash Keys Build" value="e.EmployeeID" />
                              <property name="Hash Keys Build.Table" value="e" />
                              <property name="Hash Keys Build.Column" value="EmployeeID" />
                              <property name="Hash Keys Build.DataType" value="Int32" />
                              <property name="Hash Keys Probe" value="et.EmployeeID" />
                              <property name="Hash Keys Probe.Table" value="et" />
                              <property name="Hash Keys Probe.Column" value="EmployeeID" />
                              <property name="Hash Keys Probe.DataType" value="Int32" />
                              <property name="Logical Operator" value="Inner Join" />
                            </properties>
                            <input>
                              <element operator="TableScan">
                                <properties>
                                  <property name="Table" value="Employees AS e" />
                                  <property name="Output List.[0]" value="e.EmployeeID" />
                                  <property name="Output List.[0].Table" value="e" />
                                  <property name="Output List.[0].Column" value="EmployeeID" />
                                  <property name="Output List.[0].DataType" value="Int32" />
                                  <property name="Output List.[1]" value="e.LastName" />
                                  <property name="Output List.[1].Table" value="e" />
                                  <property name="Output List.[1].Column" value="LastName" />
                                  <property name="Output List.[1].DataType" value="String" />
                                  <property name="Output List.[2]" value="e.FirstName" />
                                  <property name="Output List.[2].Table" value="e" />
                                  <property name="Output List.[2].Column" value="FirstName" />
                                  <property name="Output List.[2].DataType" value="String" />
                                  <property name="Statistics.Open Count" value="1" />
                                  <property name="Statistics.Row Count" value="9" />
                                  <property name="Statistics.Average Row Count" value="9" />
                                </properties>
                                <input />
                              </element>
                              <element operator="TableScan">
                                <properties>
                                  <property name="Table" value="EmployeeTerritories AS et" />
                                  <property name="Output List.[0]" value="et.EmployeeID" />
                                  <property name="Output List.[0].Table" value="et" />
                                  <property name="Output List.[0].Column" value="EmployeeID" />
                                  <property name="Output List.[0].DataType" value="Int32" />
                                  <property name="Output List.[1]" value="et.TerritoryID" />
                                  <property name="Output List.[1].Table" value="et" />
                                  <property name="Output List.[1].Column" value="TerritoryID" />
                                  <property name="Output List.[1].DataType" value="String" />
                                  <property name="Statistics.Open Count" value="1" />
                                  <property name="Statistics.Row Count" value="49" />
                                  <property name="Statistics.Average Row Count" value="49" />
                                </properties>
                                <input />
                              </element>
                            </input>
                          </element>
                          <element operator="TableScan">
                            <properties>
                              <property name="Table" value="Territories AS t" />
                              <property name="Output List.[0]" value="t.TerritoryID" />
                              <property name="Output List.[0].Table" value="t" />
                              <property name="Output List.[0].Column" value="TerritoryID" />
                              <property name="Output List.[0].DataType" value="String" />
                              <property name="Output List.[1]" value="t.TerritoryDescription" />
                              <property name="Output List.[1].Table" value="t" />
                              <property name="Output List.[1].Column" value="TerritoryDescription" />
                              <property name="Output List.[1].DataType" value="String" />
                              <property name="Output List.[2]" value="t.RegionID" />
                              <property name="Output List.[2].Table" value="t" />
                              <property name="Output List.[2].Column" value="RegionID" />
                              <property name="Output List.[2].DataType" value="Int32" />
                              <property name="Statistics.Open Count" value="1" />
                              <property name="Statistics.Row Count" value="53" />
                              <property name="Statistics.Average Row Count" value="53" />
                            </properties>
                            <input />
                          </element>
                        </input>
                      </element>
                    </input>
                  </element>
                  <element operator="Concatenation">
                    <properties>
                      <property name="Statistics.Open Count" value="53" />
                      <property name="Statistics.Row Count" value="23" />
                      <property name="Statistics.Average Row Count" value="0" />
                    </properties>
                    <input>
                      <element operator="Filter">
                        <properties>
                          <property name="Statistics.Open Count" value="53" />
                          <property name="Statistics.Row Count" value="19" />
                          <property name="Statistics.Average Row Count" value="0" />
                          <property name="Predicate" value="TRUE AND t.RegionID = 1" />
                        </properties>
                        <input>
                          <element operator="ConstantScan">
                            <properties>
                              <property name="Empty" value="False" />
                              <property name="Statistics.Open Count" value="53" />
                              <property name="Statistics.Row Count" value="53" />
                              <property name="Statistics.Average Row Count" value="1" />
                            </properties>
                            <input />
                          </element>
                        </input>
                      </element>
                      <element operator="NestedLoops">
                        <properties>
                          <property name="Logical Operator" value="Left Anti Semi Join" />
                          <property name="Statistics.Open Count" value="34" />
                          <property name="Statistics.Row Count" value="4" />
                          <property name="Statistics.Average Row Count" value="0" />
                        </properties>
                        <input>
                          <element operator="ConstantScan">
                            <properties>
                              <property name="Empty" value="False" />
                              <property name="Statistics.Open Count" value="34" />
                              <property name="Statistics.Row Count" value="34" />
                              <property name="Statistics.Average Row Count" value="1" />
                            </properties>
                            <input />
                          </element>
                          <element operator="IndexSpool">
                            <properties>
                              <property name="Statistics.Open Count" value="34" />
                              <property name="Statistics.Row Count" value="30" />
                              <property name="Statistics.Average Row Count" value="1" />
                              <property name="Logical Operator" value="Eager Spool" />
                              <property name="With Stack" value="False" />
                              <property name="Index" value="et.TerritoryID" />
                              <property name="Index.Table" value="et" />
                              <property name="Index.Column" value="TerritoryID" />
                              <property name="Index.DataType" value="String" />
                              <property name="Probe" value="t.TerritoryID" />
                            </properties>
                            <input>
                              <element operator="TableScan">
                                <properties>
                                  <property name="Table" value="EmployeeTerritories AS et" />
                                  <property name="Output List.[0]" value="et.TerritoryID" />
                                  <property name="Output List.[0].Table" value="et" />
                                  <property name="Output List.[0].Column" value="TerritoryID" />
                                  <property name="Output List.[0].DataType" value="String" />
                                  <property name="Statistics.Open Count" value="1" />
                                  <property name="Statistics.Row Count" value="49" />
                                  <property name="Statistics.Average Row Count" value="49" />
                                </properties>
                                <input />
                              </element>
                            </input>
                          </element>
                        </input>
                      </element>
                    </input>
                  </element>
                </input>
              </element>
            </input>
          </element>
        </input>
      </element>
    </executionPlan>
  </expectedPlan>
</test>